<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Create extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
	public $base_uri = array();
			
	function __construct(){
			parent::__construct();
			$main =   & get_config();
			$this->base_uri['base_url'] = $main['base_url'];
			
			$idd = $this->session->userdata('iduser');
			
			
			if(isset($idd) and $this->input->get('iduser') != "0"){
				//$this->session->set_userdata('session_id', $this->input->get('iduser'));
				$this->session->set_userdata('id_user', $this->input->get('iduser'));
			};
			
						
	
	}
	
	public function index()
	{
		//var_dump($this->session->all_userdata());
		//echo 'id^'.$this->input->get('iduser');

		if($this->input->get('iduser') !== '0'){
			
				if($this->input->get('mon')){
					$mon = $this->input->get('mon');
				}else{
				    $mon = 0;
				}
			
				$this->load->model('Basemodel');
						
				$data = array();
				$data['data'] = $this->Basemodel->get($mon); 
				
				$data['turs'] = $this->Basemodel->gettur($this->session->userdata('id_user'));
						
				$data['base_url'] = $this->base_uri['base_url'];
				$data['id_user'] = $this->session->userdata('id_user');
				
				if($this->session->userdata('id_user') == 430){
					$data['date'] = $this->Basemodel->getdates();
				}
				
				$data['mon'] = $mon;

				
				
				$this->load->view('header_view');
				if($this->session->userdata('id_user') == 430) $this->load->view('main_view', $this->base_uri);
				$this->load->view('create_message', $data);
		}else{
				$this->session->unset_userdata('id_user');
				$this->load->view('header_view');
				echo "Необходима регистрация";
		}
	}
	
	public function mode()
	{
		//var_dump($this->session->all_userdata());
		$this->load->model('Formmodel');
		$data = array();
	    $data['data'] = $this->Formmodel->get();
						
		$this->load->view('header_view');
		$this->load->view('main_view', $this->base_uri);
		$this->load->view('mode_view', $data);
	}
	
	public function creater()
	{
		if($this->input->get('type') == "2"){
			if((int)$this->input->get('fcheck') > 1){
				$pilot = Array();
				for($i=0; $i < (int)$this->input->get('fcheck')+1; $i++){
					$pilot[$i] = $this->input->get('pilot'.$i);
				};
			};
		}elseif($this->input->get('type') == "1"){
			$pilot = Array($this->input->get('comone'),$this->input->get('comtwo'));			
		}
		
		
		
		if($this->input->get('turname')){
			echo $this->input->get('turname');
			$this->load->model('Createmodel');
			echo $this->Createmodel->put(serialize($pilot));
		}
		
		$this->load->model('Createlistmodel');
				
		$data = array();
		$data['base_uri'] = $this->base_uri;
		$data['data'] = $this->Createlistmodel->getlist();
		
		$this->load->view('header_view');
		$this->load->view('main_view', $this->base_uri);
		$this->load->view('create_view', $data);
	}
	
	public function moderat()
	{
		if($this->input->get('type') == "2"){
			if((int)$this->input->get('fcheck') > 1){
				$pilot = Array();
				for($i=0; $i < (int)$this->input->get('fcheck')+1; $i++){
					$pilot[$i] = $this->input->get('pilot'.$i);
				};
			};
		}elseif($this->input->get('type') == "1"){
			$pilot = Array($this->input->get('comone'),$this->input->get('comtwo'));			
		}
		
		
		
		if($this->input->get('turname')){
			echo $this->input->get('turname');
			$this->load->model('Createmodel');
			echo $this->Createmodel->mod(serialize($pilot));
		}
		
		/*
		$this->load->view('header_view');
		$this->load->view('main_view', $this->base_uri);
		$this->load->view('create_view', $this->base_uri);
		*/
		
		$this->load->helper('url');	
	    redirect('/create/');
	}
	
	public function drop(){
	    //$this->input->get('id');
	    
	    $this->load->model('Createmodel');
	    $this->Createmodel->drop($this->input->get('id'));
	    
	    $this->load->helper('url');	
	    redirect('/create/');
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
